package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.entity.vo.QueryEarningsParam;
import io.renren.modules.app.entity.vo.SelectEarningsData;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.app.entity.EarningsRecordingEntity;
import io.renren.modules.app.service.EarningsRecordingService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 收益记录表
 *
 *
 *
 * @date 2022-04-20 22:37:45
 */
@RestController
@RequestMapping("app/earningsrecording")
public class EarningsRecordingController {
    @Autowired
    private EarningsRecordingService earningsRecordingService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:earningsrecording:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = earningsRecordingService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{earningsId}")
    @RequiresPermissions("generator:earningsrecording:info")
    public R info(@PathVariable("earningsId") Long earningsId){
		EarningsRecordingEntity earningsRecording = earningsRecordingService.getById(earningsId);

        return R.ok().put("earningsRecording", earningsRecording);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:earningsrecording:save")
    public R save(@RequestBody EarningsRecordingEntity earningsRecording){
        earningsRecording.setCreateTime(new Date());
		earningsRecordingService.save(earningsRecording);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:earningsrecording:update")
    public R update(@RequestBody EarningsRecordingEntity earningsRecording){
		earningsRecordingService.updateById(earningsRecording);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:earningsrecording:delete")
    public R delete(@RequestBody Long[] earningsIds){
		earningsRecordingService.removeByIds(Arrays.asList(earningsIds));

        return R.ok();
    }

    /**
     * 分页获取收益记录
     */
    @Login
    @GetMapping("queryEarningsRecording")
    public R queryEarningsRecording(QueryEarningsParam earningsParam){
        SelectEarningsData earningsData = earningsRecordingService.queryEarningsRecording(earningsParam);
        return R.ok().put("data",earningsData);
    }

}
